const Core = require('@alicloud/pop-core');

var client = new Core({
  accessKeyId: 'LTAI5tAzf1q9UNxZ2nhc6584',
  accessKeySecret: 'nLINLJ8nmrDxgNpSumt3q0PUjpZTRe',
  // securityToken: '<your-sts-token>', // use STS Token
  endpoint: 'https://dysmsapi.aliyuncs.com',
  apiVersion: '2017-05-25'
});

//生成六位数
let randomCode = () => {
  return +Math.random().toFixed(6).slice(-6); 
}

const params = {
  //PhoneNumbers,//接收短信的手机号码
  "SignName": "阿里云短信测试", //短信签名名称
  "TemplateCode": "SMS_154950909",//短信模板CODE
  //"TemplateParam": JSON.stringify({ 'code': randomCode() })//短信模板变量对应的实际值
}

const requestOption = {
  method: 'POST',
  formatParams: false,
};

let sendPhoneCode = (PhoneNumbers,code) => {
  return client.request('SendSms', {...params,PhoneNumbers,TemplateParam:JSON.stringify({code})}, requestOption)
}



module.exports = {
  sendPhoneCode,
  randomCode
}
